// 云函数入口文件
const cloud = require('wx-server-sdk')

cloud.init()

// 云函数入口函数
exports.main = async (event, context) => {
  var DB = cloud.database().collection('bin_inf');
  var _ = cloud.database().command;
  if (event.type == 'up_bin') {
    return await DB.doc(event._id).update({
      data: {
        bing_box: _.push({
          index: event.index,
          openid: event.openid
        })
      }
    })
  }else if(event.type == 'down_bin'){
    return await DB.doc(event._id).update({
      data: {
        bing_box: _.pull({
          index: event.index
        })
      }
    })
  }

} 